package com.cskaoyan.wordmemorize.controller.app;


import com.cskaoyan.wordmemorize.auth.SaUserCheckPermission;
import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/review")
public class UserReviewController {

    @Autowired
    UserReviewService userReviewService;


    @PostMapping("/voc")
    public Result<?> addUserRovRev(@RequestBody List<Long> vocIds) {
        // userId从后端获取
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.addUserRovRev(vocIds, userId);
        return Result.ok();
    }

    @GetMapping("/data")
    public Result<DownLoadUserReviewDTO> downloadUserReviewData(PageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        DownLoadUserReviewDTO dto = userReviewService.downloadUserReviewData(pageRequest, userId);
        return Result.ok(dto);
    }

    @PostMapping("/data")
    public Result<?> synchronizeUserReviewData(@RequestBody UserReviewDataCommand command) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.synchronizeUserReviewData(command, userId);
        return Result.ok();
    }



}
